package parser;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;

import java.util.List;
import java.util.Vector;


import javax.xml.parsers.ParserConfigurationException;

import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import org.xml.sax.SAXException;


public class XMLParser
{   
	static org.jdom.Document doc;
	Vector[] vector; 
	public void read(String message) throws ParserConfigurationException, SAXException, IOException
	{
		
		if(openXml(message)){
			vector = getDATA();
			System.out.print("gg");
	    }
	}
	
private static boolean openXml(String data){
		
		try {
			SAXBuilder builder = new SAXBuilder();
			InputStream in = new StringBufferInputStream(data);
			
			doc = builder.build(in);	
		} catch (Exception e) {
//			}
			return false;
		}
		return true;
	}
public Vector[] getDATA(){
	try{
		Element xmlRoot = doc.getRootElement();
		System.out.print(xmlRoot.getName());
		System.out.print(xmlRoot.getChild("name").getText());
	List l = xmlRoot.getChildren();
	System.out.print((Element)l.get(0));
//		thyPnr.pnrNumber = PnrElm.getChild("pnrNumber").getTextTrim();
//		thyPnr.header = PnrElm.getChild("header").getTextTrim();
//		thyPnr.pnrView = PnrElm.getChild("pnrView").getTextTrim();
//
//		/** passengers **/
//		Passengers passengers = new Passengers();
//		Passenger passenger = null;
//		Vector passengerVector = new Vector();
//		List PassengerLst = PnrElm.getChild("Passengers").getChildren("Passenger");
//		Iterator PassengerItr = PassengerLst.iterator();
//		while(PassengerItr.hasNext()){
//			passenger = new Passenger();
//			Element PassengerElm = (Element) PassengerItr.next();
//			passenger.name = PassengerElm.getChild("name").getTextTrim(); 
//			passenger.surname = PassengerElm.getChild("surname").getTextTrim(); 
//			passenger.title = PassengerElm.getChild("title").getTextTrim(); 
//			passengerVector.add(passenger);
//		}
	}catch(Exception e){
//			thyPnr = null;
		}
	
	
	return vector;
	
	
}
}

